package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.OmOrgAdmin;
import com.augurit.common.system.web.org.form.OmOrgAdminForm;


public class OmOrgAdminConverter {
	
	public static List<OmOrgAdminForm> convertToForm(List list){
		if(list != null && list.size() > 0){
			List<OmOrgAdminForm> result = new ArrayList();
			
			for(int i=0; i<list.size(); i++){
				Object[] objs = (Object[])list.get(i);
				OmOrgAdmin entity = (OmOrgAdmin)objs[0];
				String orgName = (String)objs[1];
				
				OmOrgAdminForm form = convertToForm(entity);
				form.setOrgName(orgName);
				
				result.add(form);
			}
			
			return result;
		}
		return null;
	}
	
	public static OmOrgAdminForm convertToForm(OmOrgAdmin entity){
		if(entity != null){
			OmOrgAdminForm form = new OmOrgAdminForm();
			form.setOaId(entity.getOaId());
			form.setOrgId(entity.getOrgId());
			form.setUserId(entity.getUserId());
			form.setAuth(entity.getAuth());
			return form;
		}
		return null;
	}
	
	public static void convertToEntity(OmOrgAdminForm form, OmOrgAdmin entity){
		if(form != null && entity != null){

			if(form.getOaId() != null)
				entity.setOaId(form.getOaId());
			
			if(form.getOrgId() != null)
				entity.setOrgId(form.getOrgId());
			
			if(form.getUserId() != null)
				entity.setUserId(form.getUserId());
			
			if(form.getAuth() != null && form.getAuth().trim().length() > 0)
				entity.setAuth(form.getAuth());
		}
	}
}
